<template>
  <div class="app-container">
    <span>弹窗类型：</span>
    <n-radio-group v-model:value="dialogType" name="radiogroup">
      <n-space>
        <n-radio v-for="song in typeList" :key="song.value" :value="song.value">
          {{ song.label }}
        </n-radio>
      </n-space>
    </n-radio-group>

    <n-space>
      <n-button @click="handleClick('ask')">ask</n-button>
      <n-button type="info" @click="handleClick('confirm')">confirm</n-button>
      <n-button type="success" @click="handleClick('message')">message</n-button>
      <n-button type="warning" @click="handleClick('open')">open</n-button>
    </n-space>
  </div>

</template>

<script setup>
import { ask, confirm, message, open } from '@tauri-apps/plugin-dialog';
import { openUrl } from "@tauri-apps/plugin-opener";
import { ref } from 'vue'
const dialogType = ref('info')
const typeList = [
  {
    value: 'info',
    label: 'info'
  },
  {
    value: 'warning',
    label: 'warning'
  },
  {
    value: 'error',
    label: 'error'
  }
]

import { useMessage } from "naive-ui";
const nMessage = useMessage();

const handleClick = async (type) => {
  switch (type) {
    case 'ask':
      const answer = await ask('今天天气不错. 是吗?', {
        title: '你该拉屎了',
        kind: dialogType.value,
      });
      console.log(answer);
      break;
    case 'confirm':
      const confirmResult = await confirm('给作者star会带来好运，\n请再次确认是否star一下', {
        title: '给作者点赞',
        kind: dialogType.value,
        okLabel: '去点star',
        cancelLabel: '取消'
      });
      if(confirmResult) {
        await openUrl('https://gitee.com/ruirui-study/tauri-wechat-naive-ui-app')
      }
      break;
    case 'message':
      await message('愿天下有钱人终成眷属', {
        title: '提示',
        kind: dialogType.value
      });
      break;
    case 'open':
      const path = await open({
        directory: true,
        multiple: false,
        title: '选择存储位置'
      });
      if (path) {
        nMessage.success(`你选择的位置为：${path}`)
      }
      break;
    default:
      break;
  }
};
</script>

<style scoped>

</style>
